function UseBagItem(itemName)
	if GetItemCount(itemName) > 0 
	and IsUsableItem(itemName) == 1
	and GetItemCooldown(itemName) == 0
	then
		UseItemByName(itemName)
	end
end

function UseTrinkets()
	local startA, _, enableA = GetInventoryItemCooldown("Player", 13)
	local startB, _, enableB = GetInventoryItemCooldown("Player", 14)
	if enableA == 1 and startA == 0 then UseInventoryItem(13) return end
	if SpellIsTargeting() == 1 and Target and Target:Exists() and not Target:IsDead() then CastAtLocation(Target:GetLocation()) end;
	if enableB == 1 and startB == 0 then UseInventoryItem(14) return end
	if SpellIsTargeting() == 1 and Target and Target:Exists() and not Target:IsDead() then CastAtLocation(Target:GetLocation()) end;
end

function PrintToChat(message)
	local vccR = "|cff00ff00ccR /> "
	-- Prevent duplications
	--[[if vLastccRMessage ~= nil
	and message == vLastccRMessage
	then
		return
	end
	vLastccRMessage = message]]
	DEFAULT_CHAT_FRAME:AddMessage(vccR .. string.join(" ", tostringall(message)), 0.41, 0.8, 0.94)
end

function ccrValidTarget(unit)
	if unit == nil then unit = "target" end;
	if UnitExists(unit) == 1
	and UnitCanAttack("Player", unit) == 1
	and UnitIsDead(unit) ~= 1
	and Target
	and Target:Exists()
	and not Target:IsDead()
	then
		return true
	else
		return false
	end
end

function SpellIDToName(spellid)
	local vSpell = GetSpellInfo(spellid)
	return vSpell
end

function ccrDistance(source, target)
	vSource = GetObjectFromUnitID(source)
	vTarget = GetObjectFromUnitID(target)
	if vSource
	and vTarget
	and vSource:Exists()
	and vTarget:Exists()
	then
		return vSource:GetDistance(vTarget)
	end
end

--function table.empty(t) for i,_ in ipairs(t) do t[i] = nil end end
function table.empty(t) 
	for i = 0, #t do
		t[i] = nil
	end
end